package ui;

import java.util.Date;

import org.uqbar.commons.utils.ApplicationContext;
import org.uqbar.commons.utils.ApplicationContextConfiguration;
import org.uqbar.commons.utils.MemoryStorage;
import org.uqbar.commons.utils.Storage;

import Aplicacion.Captura;
import Aplicacion.Imagen;
import Aplicacion.Infraccion;
import Aplicacion.TipoInfraccion;
import Aplicacion.Vehiculo;
import Aplicacion.Zona;
import Homes.CapturasHome;
import Homes.InfraccionesHome;
import Homes.VehiculosHome;
import Mocks.MockAnalizadorSuccess;

public class FotoMultasContext implements ApplicationContextConfiguration {

        //@Override
        public void configure(ApplicationContext instance) {
                installSingletons();
                
                TipoInfraccion tipo1= new TipoInfraccion("Mal Estacionado",10,11);
                TipoInfraccion tipo2= new TipoInfraccion("Exceso de velocidad",10,11);
                Infraccion infraccion1 = new Infraccion(tipo1, new Date(), new Zona("5555-5555"));
                Infraccion infraccion2 = new Infraccion(tipo2, new Date(), new Zona("5555-5555"));
                
                Vehiculo vehiculo1 = new Vehiculo("AAA-000");
                Vehiculo vehiculo2 = new Vehiculo("AAA-001");
                Vehiculo vehiculo3 = new Vehiculo("AAA-002");
                
                Captura captura = new Captura(new Imagen(), infraccion1);
                                        
                this.makePersistent(Infraccion.class, infraccion1);
                this.makePersistent(Infraccion.class, infraccion2);
                
                this.makePersistent(Vehiculo.class, vehiculo1);
                this.makePersistent(Vehiculo.class, vehiculo2);
                this.makePersistent(Vehiculo.class, vehiculo3);
                
                this.makePersistent(Captura.class, captura);
        }

        // ********************************************************
        // ** Internal
        // ********************************************************

        private <T> T makePersistent(Class<? super T> type, T object) {
                ApplicationContext.getInstance().getHome(type).add(object);
                return object;
        }

        private void installSingletons() {
                ApplicationContext.getInstance().configureSingleton(Storage.class, new MemoryStorage());
                
                CapturasHome capturasHome = new CapturasHome(Captura.class);
                capturasHome.setAnalizadorImagenes(new MockAnalizadorSuccess());
                
                ApplicationContext.getInstance().configureHome(Captura.class, capturasHome);
                ApplicationContext.getInstance().configureHome(Infraccion.class, new InfraccionesHome());
                ApplicationContext.getInstance().configureHome(Vehiculo.class, new VehiculosHome());
        }
}